<template>
    <div>
        <div id="slider" class="mui-slider ">
				<div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
					<div class="mui-scroll">
						<a v-for="item in cates" :key="item.id" :class="['mui-control-item',item.id==0?'mui-active':'']" @click="getImage(item.id)">
							{{ item.title }}
						</a>
						
					</div>
				</div>
                <!-- 内容图片 -->
                <ul class="photolist-show">
                    <router-link :to="'/home/photoinfo/'+item.id" tag="li" v-for="item in list" :key="item.img_url">
                        <img v-lazy="item.img_url">
                        <div class="phototext-show">
                            <h3>{{ item.title }}</h3>
                             <p>{{ item.abstract }}</p>
                        </div>
                    </router-link>
                </ul>

			</div>
    </div>
</template>
<script>
//1.导入 mui 的js 文件
import mui from "../../lib/mui/js/mui.min.js"
//导入弹窗组件
import { Toast } from "mint-ui"

export default{
    data(){
        return{
            cates: [],
            list:[]
        }
    },
    created(){
        this.getAllcategory()
        this.getImage(0)//默认显示全部图片
    },
    methods:{
        getAllcategory(){//获取列表数据
            this.$http.get("../../api/categorylist.json").then(result => {
                if(result.body.status === 0 ){
                    //手动添加一个全部项
                    result.body.message.unshift({
                        title: "全部",
                        id: 0
                    })
                    this.cates=result.body.message
                }else{
                    Toast("获取列表失败")
                }
            })
        },
        getImage(id){
            this.$http.get("../../api/categorylist.json").then(result => {
                if(result.body.status === 0){
                    //判断传入的id是否为0，如果为零，则把所有的id对应的图片都显示到全部中
                    if(id==0){
                        //获取对应id的图片
                        var listImage1=result.body.message[0].images.message//家居生活
                        var listImage2=result.body.message[1].images.message//摄影设计
                        var listImage3=result.body.message[2].images.message//明星美女
                        //遍历摄影设计
                        listImage2.forEach(element => {
                            listImage1.unshift(element)
                        })
                        //循环遍历第三列的图片
                        listImage3.forEach(element => {
                            //将第三列明星美女图片加到列1家居生活中
                            listImage1.push(element)
                        });
                        this.list=listImage1
                        return 
                        
                    }
                    var listImages=result.body.message[id-1].images//获取对应id的图片
                    this.list=listImages.message
                }else{
                    Toast("暂无图片资源")
                }
            })
        }
    },
    mounted(){
        //需要放到mounted这个生命周期中
        //2.初始化 滑动控件 
        mui('.mui-scroll-wrapper').scroll({
            deceleration: 0.0005//flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
        })
    }
}
</script>
<style lang="less" scoped>
*{
    touch-action: pan-y;//不显示警告
}
img[lazy=loading] {
  width: 40px;
  height: 300px;
  margin: auto;
}
.photolist-show{
    list-style: none;
    padding: 0 5px;
    li{
        position: relative;
        margin-bottom: 5px;
        img{
            vertical-align: bottom;
        }
    }
    
}
.phototext-show{
    width: 100%;
    height: auto;
    
    color: #ffffff;
    background-color: rgba(0,0,0,0.4);
    position:absolute;
    bottom: 0px;
    padding: 0 5px;
    h3{
            font-size: 14px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
    p{
        font-size: 13px;
        text-indent: 2em;
        max-height: 60px;
        overflow: hidden;
        text-overflow: ellipsis;
        -ms-text-overflow: ellipsis;
        -o-text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 3;
    }
}
.mui-scroll{
    background-color: #ffffff;
    position: fixed;
}
</style>

